package com.udian.frame.code;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class TestMysql {
	
	static String  url = "jdbc:mysql://localhost:3306/db_line?useUnicode=true&characterEncoding=utf8" ;    
	static String  username = "root" ;   
	static String password = "" ; 
	private static Connection conn = null;
	
	public static void initConnection(){
		 //加载驱动
       String className = "com.mysql.jdbc.Driver"; 
       try {
           Class.forName(className);
           System.out.println("1、加载成功");
       } catch (ClassNotFoundException e) {
           e.printStackTrace();System.out.println("找不到驱动程序类 ，加载驱动失败！");   
           e.printStackTrace() ;   
       }
       try{   
           conn = DriverManager.getConnection(url, username, password);
           System.out.println("2、连接成功");
       }catch(SQLException se){   
           System.out.println("数据库连接失败！");   
           se.printStackTrace() ;   
       }
	}
	public static void main(String[] args) throws Exception {
		initConnection();
		
		String sql = "select id, city_code AS cityCode, name, stop_code AS stopCode, lng_bd AS lngBd, lat_bd AS latBd, location, stop_type AS stopType, platform_type AS platformType, parking_space AS parkingSpace, transfer_metrio AS transferMetrio, version, street, road, district, department, area, address, available, create_date AS createDate, create_user AS createUser, modify_date AS modifyDate, modify_user AS modifyUser from `basis_stop` WHERE name like CONCAT('%', ?, '%') and available = ? order by name ";
		PreparedStatement ps = conn.prepareStatement(sql);
		ps.setString(1, "西丽湖");
		ps.setString(2, "1");
		//ps.setString(3, "name");
		/*ps.setInt(4, 1);
		ps.setInt(5, 5);*/
		ResultSet resultSet = ps.executeQuery();
		while (resultSet.next()) {
			System.out.println(resultSet.getString(3));
		}
		resultSet.close();
		ps.close();
	}
}
